﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;
using System.Data.OleDb;
using System.Configuration;
using XMK.Tadong.Biz;

namespace XMK.Tadong.Web.TJ
{
    public partial class TJ_TJGCLTJ : System.Web.UI.Page
    {
        #region 变量

        string UserCode = "", MacStr = "";//记录当前用户
        private tj_service clientser;
        string strjb, stryc, strQXCW1, strQXCW2, DownRight = "";//记录当前井别,油层,取心层位1,取心层位2,井号
        double dlWZJS, dlJC, dlYXCD, dlSHL, dlDJSD1, dlDJSD2;

        #endregion 变量

        #region 事件处理程序

        protected void Page_Load(object sender, EventArgs e)
        {
            //Response.Charset = "GB2312";


            //client=new Service2 ();
            clientser = new tj_service();
            if (!IsPostBack)
            {
                UserCode = Session["user_id"].ToString();

                usertb.Text = UserCode;

                MacStr = Session["MacAddress"].ToString();
                if (DownRight == "0")
                {
                    btnDownLoad.Visible = false;
                }
                tj_service serclient = new tj_service();
                string strJHList = "";
                string strSql = "select distinct jh  from  giswell where jh in (select jh from xmk_az01)";
                DataSet ds = serclient.GetDataSet(strSql);
                int numcount = ds.Tables[0].Rows.Count;
                if (numcount > 20)
                    numcount = 20;  //如果满足条件的井太多，后面构造的查询语句会过长，导致错误，所以这里限制只显示２０口井

                for (int i = 0; i < numcount; i++)
                {
                    strJHList += "," + ds.Tables[0].Rows[i][0].ToString();
                }
                if (strJHList != "")
                    strJHList = strJHList.Substring(1, strJHList.Length - 1);
                input_tb.Text = strJHList;

            }
        }

        private void ButtonYC_Click(object sender, System.EventArgs e)
        {
            string jhstring = "";//要统计的井号
            int recordnumber = 0;//统计的记录数目
            Session["tempjb"] = "";//存储当前井别
            Session["tempyc"] = "";//存储当前层位
            stryc = YCDDL.SelectedItem.Text;
            showYCDG.Visible = true;
            showJBDG.Visible = false;
            showdg.Visible = false;

            try
            {
                //删除该层位的统计记录
                string strsel = "delete from XMK_A_Z_ZJ03 where (YC='" + stryc + "')";
                tj_service service = new tj_service();
                YQCJDBLL bll = new YQCJDBLL();
                bll.inserData(strsel);
                string strsql = "select distinct(JH),JB from XMK_AZ01 where (XMK_AZ01.YC='" + YCDDL.SelectedValue + "') and JH in(" + tb.Text + ") ";
                DataSet dr = clientser.GetDataSet(strsql);

                if (dr.Tables[0].Rows.Count == 0)
                {
                    resultLabel.Text = stryc + "没有数据!";
                    refreshpage();
                }
                else
                {
                    for (int j = 0; j < dr.Tables[0].Rows.Count; j++)
                    {
                        dlWZJS = dlJC = dlYXCD = dlDJSD1 = dlDJSD2 = dlSHL = 0.0;
                        jhstring = dr.Tables[0].Rows[j][0].ToString();
                        strjb = dr.Tables[0].Rows[j][1].ToString();
                        //计算取心进尺和岩心收获率
                        string str = "select a.WZJS,b.DJSD1,b.DJSD2,(b.DJSD2-b.DJSD1) as JC,b.QXCW1,b.QXCW2,b.YXCD,(b.YXCD/(b.DJSD2-b.DJSD1)) as SHL1 from AZ02 a,AZ13 b where  (a.JH ='" + jhstring + "') and (b.JH ='" + jhstring + "') and  (b.DJSD2>b.DJSD1) order by b.DJSD1";
                        DataSet ds = clientser.GetDataSet(str);//(AZ02.JH ='杜606') and (AZ13.JH ='杜606')";//
                        DataTable dt = ds.Tables[0];
                        int num = dt.Rows.Count;
                        if (num != 0)
                        {
                            recordnumber++;
                            strQXCW1 = strQXCW2 = "";
                            dlWZJS = Convert.ToDouble(dt.Rows[0][0].ToString());

                            for (int i = 0; i < num; i++)
                            {
                                dlDJSD1 = Convert.ToDouble(dt.Rows[0][1].ToString());
                                dlDJSD2 = Convert.ToDouble(dt.Rows[i][2].ToString());
                                dlJC += Convert.ToDouble(dt.Rows[i][2].ToString()) - Convert.ToDouble(dt.Rows[i][1].ToString());
                                if (dt.Rows[i][6].ToString() != "")
                                {
                                    dlYXCD += Convert.ToDouble(dt.Rows[i][6].ToString());
                                }
                                if (dt.Rows[i][4].ToString() != "")
                                {
                                    string ss = dt.Rows[i][4].ToString();
                                    if (strQXCW1.Length == 0)
                                    {
                                        strQXCW1 += ss + ",";
                                    }
                                    else
                                    {
                                        ss = ss.ToLower();
                                        strQXCW1 = strQXCW1.ToLower();
                                        int at = strQXCW1.IndexOf(ss, 0, strQXCW1.Length - 1);
                                        if (at == -1)
                                        {
                                            strQXCW1 += ss + ",";
                                        }
                                    }
                                }
                                if (dt.Rows[i][5].ToString() != "")
                                {
                                    string ss = dt.Rows[i][5].ToString();
                                    if (strQXCW2.Length == 0)
                                    {
                                        strQXCW2 += ss + ",";
                                    }
                                    else
                                    {
                                        ss = ss.ToLower();
                                        strQXCW2 = strQXCW2.ToLower();
                                        int at = strQXCW2.IndexOf(ss, 0, strQXCW2.Length - 1);
                                        if (at == -1)
                                        {
                                            strQXCW2 += ss + ",";
                                        }
                                    }
                                }
                            }
                            if (strQXCW1 != "")
                            {
                                strQXCW1 = strQXCW1.Substring(0, strQXCW1.Length - 1);
                            }
                            if (strQXCW2 != "")
                            {
                                strQXCW2 = strQXCW2.Substring(0, strQXCW2.Length - 1);
                            }
                            dlSHL = dlYXCD / dlJC;
                            dlWZJS = Math.Round(dlWZJS, 2);
                            dlJC = Math.Round(dlJC, 2);
                            dlYXCD = Math.Round(dlYXCD, 2);
                            dlSHL = Math.Round(dlSHL, 2);
                            clientser.WriteToZJ(usertb.Text, jhstring, stryc, strjb, num, dlWZJS, dlDJSD1, dlDJSD2, dlJC, strQXCW1, strQXCW2, dlYXCD, dlSHL);
                            resultLabel.Text = stryc + " 成功统计!";
                        }
                    }
                    resultLabel.Text = "统计数为：" + recordnumber;
                    string strds = "select JH,JB,WZJS,DJSD1,DJSD2,QXJC,QXCW1,QXCW2,YXCD,SHL from XMK_A_Z_ZJ03 where  (YC='" + stryc + "')and(TJR='" + usertb.Text + "') order by JH,DJSD1";

                    DataSet dataset = clientser.GetDataSet(strds);
                    if (dataset.Tables[0].Rows.Count == 0)
                    {
                        resultLabel.Text = stryc + "没有统计数据！";
                        refreshpage();
                    }
                    else
                    {
                        showYCDG.DataSource = dataset;
                        showYCDG.DataBind();
                        string sql = "";
                        sql = "select JB as 井别,WZJS as 完钻井深,DJSD1 as 顶界深度,DJSD2 as 底界深度,QXJC as 取心进尺,YXCD as 岩心长度,SHL as 收获率  from XMK_A_Z_ZJ03 where (JB='" + strjb + "')and(TJR='" + usertb.Text + "') order by JH,DJSD1";
                        BindPeople(sql);
                        btnDownLoad.Enabled = true;
                        Session["tempjb"] = strjb;
                        Session["tempyc"] = stryc;
                    }
                }
            }
            catch (Exception ee)
            {
                throw ee;
            }



        }

        private void JBButton_Click(object sender, System.EventArgs e)
        {
            string jhstring = "";
            int recordnumber = 0;

            Session["tempjb"] = "";
            Session["tempyc"] = "";
            showJBDG.Visible = true;
            showYCDG.Visible = false;
            showdg.Visible = false;

            try
            {
                string strsel = "delete from XMK_A_Z_ZJ03 where (JB='" + strjb + "')";
                
                YQCJDBLL bll = new YQCJDBLL();
                bll.inserData(strsel);
                string strsql = "select distinct(JH),YC from XMK_AZ01 where (XMK_AZ01.JB='" + JBDDL.SelectedValue + "') and JH in(" + tb.Text + ")";
                DataSet dr = clientser.GetDataSet(strsql);
                if (dr.Tables[0].Rows.Count == 0)
                {
                    resultLabel.Text = strjb + "没有数据!";
                    refreshpage();
                }
                else
                {
                    for (int j = 0; j < dr.Tables[0].Rows.Count; j++)
                    {
                        dlWZJS = dlJC = dlYXCD = dlDJSD1 = dlDJSD2 = dlSHL = 0.0;
                        jhstring = dr.Tables[0].Rows[j][0].ToString();
                        stryc = dr.Tables[0].Rows[j][1].ToString();
                        //jhstring=jhstring.Substring(0,jhstring.Length -1);				
                        string str = "select a.WZJS,b.DJSD1,b.DJSD2,(b.DJSD2-b.DJSD1) as JC,b.QXCW1,b.QXCW2,b.YXCD,(b.YXCD/(b.DJSD2-b.DJSD1)) as SHL1 from AZ02 a,AZ13 b where (a.JH ='" + jhstring + "') and (b.JH ='" + jhstring + "')order by b.DJSD1";
                        DataSet ds = clientser.GetDataSet(str);
                        DataTable dt = ds.Tables[0];

                        int num = dt.Rows.Count;
                        if (num != 0)
                        {
                            dlWZJS = 0;
                            strQXCW1 = strQXCW2 = "";
                            recordnumber++;
                            dlWZJS = Convert.ToDouble(dt.Rows[0][0].ToString());
                            for (int i = 0; i < num; i++)
                            {

                                dlDJSD1 = Convert.ToDouble(dt.Rows[0][1].ToString());
                                dlDJSD2 = Convert.ToDouble(dt.Rows[i][2].ToString());

                                dlJC = dlJC + (Convert.ToDouble(dt.Rows[i][2].ToString()) - Convert.ToDouble(dt.Rows[i][1].ToString()));


                                if (dt.Rows[i][6].ToString() != "")
                                {
                                    dlYXCD += Convert.ToDouble(dt.Rows[i][6].ToString());
                                }
                                if (dt.Rows[i][4].ToString() != "")
                                {
                                    string ss = dt.Rows[i][4].ToString();
                                    if (strQXCW1.Length == 0)
                                    {
                                        strQXCW1 += ss + ",";
                                    }
                                    else
                                    {
                                        ss = ss.ToLower();
                                        strQXCW1 = strQXCW1.ToLower();
                                        int at = strQXCW1.IndexOf(ss, 0, strQXCW1.Length - 1);
                                        if (at == -1)
                                        {

                                            strQXCW1 += ss + ",";
                                        }
                                    }
                                }
                                if (dt.Rows[i][5].ToString() != "")
                                {
                                    string ss = dt.Rows[i][5].ToString();
                                    if (strQXCW2.Length == 0)
                                    {
                                        strQXCW2 += ss + ",";
                                    }
                                    else
                                    {
                                        ss = ss.ToLower();
                                        strQXCW2 = strQXCW2.ToLower();
                                        int at = strQXCW2.IndexOf(ss, 0, strQXCW2.Length - 1);
                                        if (at == -1)
                                        {
                                            strQXCW2 += ss + ",";
                                        }
                                    }
                                }
                            }
                            if (strQXCW1 != "")
                            {
                                strQXCW1 = strQXCW1.Substring(0, strQXCW1.Length - 1);
                            }
                            if (strQXCW2 != "")
                            {
                                strQXCW2 = strQXCW2.Substring(0, strQXCW2.Length - 1);
                            }
                            dlSHL = dlYXCD / dlJC;
                            dlWZJS = Math.Round(dlWZJS, 2);
                            dlJC = Math.Round(dlJC, 2);
                            dlYXCD = Math.Round(dlYXCD, 2);
                            dlSHL = Math.Round(dlSHL, 2);
                            clientser.WriteToZJ(usertb.Text, jhstring, stryc, JBDDL.SelectedValue, num, dlWZJS, dlDJSD1, dlDJSD2, dlJC, strQXCW1, strQXCW2, dlYXCD, dlSHL);
                            resultLabel.Text = strjb + " 成功统计!";
                        }
                    }
                    resultLabel.Text = "统计数为：" + recordnumber;
                    string strds = "select JH,JB,YC,WZJS,DJSD1,DJSD2,QXJC,QXCW1,QXCW2,YXCD,SHL from XMK_A_Z_ZJ03 where (JB='" + JBDDL.SelectedValue + "')and(TJR='" + usertb.Text + "') order by JH,DJSD1";

                    DataSet dataset = clientser.GetDataSet(strds);
                    if (dataset.Tables[0].Rows.Count == 0)
                    {
                        resultLabel.Text = "没有统计数据！";
                        refreshpage();
                    }
                    else
                    {
                        showJBDG.DataSource = dataset;
                        showJBDG.DataBind();
                        string sql = "";
                        sql = "select YC as 油层,WZJS as 完钻井深,DJSD1 as 顶界深度,DJSD2 as 底界深度,QXJC as 取心进尺,YXCD as 岩心长度,SHL as 收获率  from XMK_A_Z_ZJ03 where (JB='" + strjb + "')and(TJR='" + usertb.Text + "') order by JH,DJSD1";
                        BindPeople(sql);
                        btnDownLoad.Enabled = true;
                        Session["tempjb"] = strjb;
                        Session["tempyc"] = stryc;
                    }
                }

            }
            catch (Exception ee)
            {
                throw ee;
                //					resultLabel.Text =strjb+"没有数据!";
                //					refreshpage();

            }
        }

        private void Button2_Click(object sender, System.EventArgs e)
        {
            string jhstring = "";
            int recordnumber = 0;
            Session["tempjb"] = "";
            Session["tempyc"] = "";

            showdg.Visible = true;
            showYCDG.Visible = false;
            showJBDG.Visible = false;

            try
            {
                string strsel = "delete from XMK_A_Z_ZJ03 where (YC='" + YCDDL.SelectedValue + "')and (JB='" + JBDDL.SelectedValue + "')";
                
                YQCJDBLL bll = new YQCJDBLL();
                bll.inserData(strsel);
                string strsql = "select distinct(JH) from XMK_AZ01 where (XMK_AZ01.JB='" + JBDDL.SelectedValue + "') and JH in(" + tb.Text + ")and(XMK_AZ01.YC='" + YCDDL.SelectedValue + "')";
                DataSet dr = clientser.GetDataSet(strsql);
                if (dr.Tables[0].Rows.Count == 0)
                {
                    resultLabel.Text = YCDDL.SelectedValue + " " + JBDDL.SelectedValue + " " + "没有数据!";
                    refreshpage();
                }
                else
                {
                    for (int j = 0; j < dr.Tables[0].Rows.Count; j++)
                    {
                        dlWZJS = dlJC = dlYXCD = dlDJSD1 = dlDJSD2 = dlSHL = 0.0;
                        jhstring = dr.Tables[0].Rows[j][0].ToString();
                        stryc = YCDDL.SelectedItem.Text;
                        //sql语句求取取心进尺和岩心收获率
                        string str = "select a.WZJS,b.DJSD1,b.DJSD2,(b.DJSD2-b.DJSD1) as JC,b.QXCW1,b.QXCW2,b.YXCD,(b.YXCD/(b.DJSD2-b.DJSD1)) as SHL1 from AZ02 a,AZ13 b where  (a.JH ='" + jhstring + "') and (b.JH ='" + jhstring + "') order by b.DJSD1";
                        DataSet ds = clientser.GetDataSet(str);
                        DataTable dt = ds.Tables[0];

                        int num = dt.Rows.Count;
                        if (num != 0)
                        {
                            dlWZJS = 0;
                            recordnumber++;
                            strQXCW1 = strQXCW2 = "";
                            dlWZJS = Convert.ToDouble(dt.Rows[0][0].ToString());

                            for (int i = 0; i < num; i++)
                            {

                                dlDJSD1 = Convert.ToDouble(dt.Rows[0][1].ToString());
                                dlDJSD2 = Convert.ToDouble(dt.Rows[i][2].ToString());
                                dlJC = dlJC + (Convert.ToDouble(dt.Rows[i][2].ToString()) - Convert.ToDouble(dt.Rows[i][1].ToString()));

                                if (dt.Rows[i][7].ToString() != "")
                                {
                                    dlSHL = Convert.ToDouble(dt.Rows[i][7].ToString());
                                }
                                if (dt.Rows[i][6].ToString() != "")
                                {
                                    dlYXCD += Convert.ToDouble(dt.Rows[i][6].ToString());
                                }
                                if (dt.Rows[i][4].ToString() != "")
                                {
                                    string ss = dt.Rows[i][4].ToString();
                                    if (strQXCW1.Length == 0)
                                    {
                                        strQXCW1 += dt.Rows[i][4].ToString() + ",";
                                    }
                                    else
                                    {
                                        ss = ss.ToLower();
                                        strQXCW1 = strQXCW1.ToLower();
                                        int at = strQXCW1.IndexOf(ss, 0, strQXCW1.Length - 1);
                                        if (at == -1)
                                        {

                                            strQXCW1 += ss + ",";
                                        }
                                    }
                                }
                                if (dt.Rows[i][5].ToString() != "")
                                {
                                    string ss = dt.Rows[i][5].ToString();
                                    if (strQXCW2.Length == 0)
                                    {
                                        strQXCW2 += ss + ",";
                                    }
                                    else
                                    {
                                        ss = ss.ToLower();
                                        strQXCW2 = strQXCW2.ToLower();
                                        int at = strQXCW2.IndexOf(ss, 0, strQXCW2.Length - 1);
                                        if (at == -1)
                                        {
                                            strQXCW2 += ss + ",";
                                        }
                                    }
                                }
                            }
                            if (strQXCW1 != "")
                            {
                                strQXCW1 = strQXCW1.Substring(0, strQXCW1.Length - 1);
                            }
                            if (strQXCW2 != "")
                            {
                                strQXCW2 = strQXCW2.Substring(0, strQXCW2.Length - 1);
                            }
                            dlSHL = dlYXCD / dlJC;
                            dlWZJS = Math.Round(dlWZJS, 2);
                            dlJC = Math.Round(dlJC, 2);
                            dlYXCD = Math.Round(dlYXCD, 2);
                            dlSHL = Math.Round(dlSHL, 2);
                            clientser.WriteToZJ(usertb.Text, jhstring, this.YCDDL.SelectedValue, this.JBDDL.SelectedValue, num, dlWZJS, dlDJSD1, dlDJSD2, dlJC, strQXCW1, strQXCW2, dlYXCD, dlSHL);
                            resultLabel.Text = stryc + " " + strjb + " " + "成功统计!";
                        }
                    }
                    resultLabel.Text = "统计数为：" + recordnumber;
                    string strds = "select JH,WZJS,DJSD1,DJSD2,QXJC,QXCW1,QXCW2,YXCD,SHL from XMK_A_Z_ZJ03 where (YC='" + this.YCDDL.SelectedValue + "')and(JB='" + this.JBDDL.SelectedValue + "')and(TJR='" + usertb.Text + "') order by JH,DJSD1";

                    DataSet dataset = clientser.GetDataSet(strds);
                    if (dataset.Tables[0].Rows.Count == 0)
                    {
                        resultLabel.Text = stryc + " " + strjb + " " + "没有统计数据！";
                        refreshpage();
                    }
                    else
                    {
                        showdg.DataSource = dataset;
                        showdg.DataBind();
                        string sql = "";
                        sql = "select JH as 井号,WZJS as 完钻井深,DJSD1 as 顶界深度,DJSD2 as 底界深度,QXJC as 取心进尺,YXCD as 岩心长度,SHL as 收获率  from XMK_A_Z_ZJ03 where (JB='" + this.JBDDL.SelectedValue + "')and(TJR='" + usertb.Text + "') order by JH,DJSD1";
                        BindPeople(sql);
                        btnDownLoad.Enabled = true;
                        Session["tempjb"] = strjb;
                        Session["tempyc"] = stryc;
                    }
                }
            }
            catch (Exception ee)
            {
            }
        }

        private void YCDDL_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (YCDDL.SelectedItem.Value != "请选择油层")
            {
                ButtonYC.Enabled = true;
            }
            else
            {
                ButtonYC.Enabled = false;
            }

            if (this.JBDDL.SelectedItem.Value != "请选择井别")
            {
                JBButton.Enabled = true;
            }
            else
            {
                JBButton.Enabled = false;
            }


            showYCDG.Visible = false;
            showJBDG.Visible = false;
            showdg.Visible = false;

            resultLabel.Text = "";

            if (YCDDL.SelectedItem.Value != "请选择油层" && this.JBDDL.SelectedItem.Value != "请选择井别")
            {
                ButtonYJ.Enabled = true;
            }
            else
            {
                ButtonYJ.Enabled = false;
            }
        }

        private void btnDownLoad_Click(object sender, System.EventArgs e)
        {
            string strsql = "";
            string strline = "";

            if (showYCDG.Visible == true)
            {
                //DataGridToExcell(showYCDG);
                strsql = "select JH,JB,WZJS,QXJC,YXCD,SHL,QXCW1,QXCW2 from XMK_A_Z_ZJ03 where (YC='" + Session["tempyc"] + "')and (TJR='" + usertb.Text + "') order by JH,DJSD1";
                strline = "井号" + "\t" + "井别" + "\t" + "完钻井深" + "\t" + "取芯进尺" + "\t" + "岩芯长度" + "\t" + "收获率" + "\t" + "取芯层位1" + "\t" + "取芯层位2";
                DataSetToExcelYC(strsql, strline);
            }

            if (showJBDG.Visible == true)
            {
                strsql = "select JH,YC,WZJS,QXJC,YXCD,SHL,QXCW1,QXCW2 from XMK_A_Z_ZJ03 where (JB='" + Session["tempjb"] + "')and (TJR='" + usertb.Text + "') order by JH,DJSD1";
                strline = "井号" + "\t" + "油层" + "\t" + "完钻井深" + "\t" + "取芯进尺" + "\t" + "岩芯长度" + "\t" + "收获率" + "\t" + "取芯层位1" + "\t" + "取芯层位2";
                DataSetToExcelYC(strsql, strline);
            }

            if (showdg.Visible == true)
            {
                strsql = "select JH,WZJS,QXJC,YXCD,SHL,QXCW1,QXCW2 from XMK_A_Z_ZJ03 where (JB='" + Session["tempjb"] + "')and (YC='" + Session["tempyc"] + "')and(TJR='" + usertb.Text + "') order by JH,DJSD1";
                strline = "井号" + "\t" + "完钻井深" + "\t" + "取芯进尺" + "\t" + "岩芯长度" + "\t" + "收获率" + "\t" + "取芯层位1" + "\t" + "取芯层位2";
                DataSetToExcelYJ(strsql, strline);
            }

        }

        private void JBDDL_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (YCDDL.SelectedItem.Value != "请选择油层")
            {
                ButtonYC.Enabled = true;
            }
            else
            {
                ButtonYC.Enabled = false;
            }
            if (this.JBDDL.SelectedItem.Value != "请选择井别")
            {
                JBButton.Enabled = true;
            }
            else
            {
                JBButton.Enabled = false;
            }

            showYCDG.Visible = false;
            showJBDG.Visible = false;
            showdg.Visible = false;
            resultLabel.Text = "";
            if (YCDDL.SelectedItem.Value != "请选择油层" && this.JBDDL.SelectedItem.Value != "请选择井别")
            {

                ButtonYJ.Enabled = true;
            }
            else
            {
                ButtonYJ.Enabled = false;
            }
        }

        private void commitJH_Click(object sender, System.EventArgs e)
        {
            string strjh = input_tb.Text;
            string strcw = "";
            strjh = strjh.Replace("，", ",");
            strjh = "'" + strjh.Replace(",", "','") + "'";
            tb.Text = strjh;
            this.FillDNL();

        }

        private void YCDDL_SelectedIndexChanged_1(object sender, System.EventArgs e)
        {
            ButtonYC.Enabled = true;
            JBButton.Enabled = false;

            showYCDG.Visible = true;
            showJBDG.Visible = false;
            showdg.Visible = false;

            resultLabel.Text = "";

        }

        #endregion 事件处理程序

        #region 函数集

        /// <summary>
        /// 生成油层和井别,并加载到下拉列表框中
        /// </summary>
        private void FillDNL()
        {
            string serfill1 = "select distinct(a.YC) from xmk_az01 a,AZ02 b,AZ13 c where a.JH in(" + tb.Text + ") and (a.JH=b.JH) and (b.JH=c.JH)";
            DataSet ds = clientser.GetDataSet(serfill1);
            if (ds.Tables[0].Rows.Count != 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    ListItem li = new ListItem();
                    li.Text = ds.Tables[0].Rows[i][0].ToString();
                    li.Value = ds.Tables[0].Rows[i][0].ToString();
                    YCDDL.Items.Add(li);
                }
            }
            serfill1 = "select distinct(a.JB) from xmk_az01 a,AZ02 b,AZ13 c where a.JH in(" + tb.Text + ") and (a.JH=b.JH) and (b.JH=c.JH)";
            ds = clientser.GetDataSet(serfill1);
            if (ds.Tables[0].Rows.Count != 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    ListItem li = new ListItem();
                    li.Text = ds.Tables[0].Rows[i][0].ToString();
                    li.Value = ds.Tables[0].Rows[i][0].ToString();
                    JBDDL.Items.Add(li);
                }
            }
            else
            {
                resultLabel.Text = "没有数据!";
                refreshpage();
            }
        }

        /// <summary>
        /// 刷新页面
        /// </summary>
        private void refreshpage()
        {

            showdg.Visible = false;
            showYCDG.Visible = false;
            showJBDG.Visible = false;


        }

        private void GetStatPicure(string sqlstr)
        {
            Literal1.Text = "";
            string strLine = "";
            strLine += "<script  LANGUAGE=javascript>";
            strLine += "\r\n";
            strLine += "<!--";
            strLine += "\r\n";
            strLine += "function button1_click(){";
            strLine += "\r\n";
            //			strLine+="Form1.VcChart1.RowCount=4";
            //			strLine += "\r\n";
            //			strLine+="Form1.VcChart1.ColumnCount=6";


            //string str="select CW,HD,MAX,MIN,AVER,LJHD,SDB from xmk_a_z_ny01 where jh='敖10'";
            DataSet ds = clientser.GetDataSet(sqlstr);
            // gChartType=

            //object[] arr=null;
            int numRow = ds.Tables[0].Rows.Count;
            int numCol = ds.Tables[0].Columns.Count;
            //strLine += "MsgBox \"HI. \"";
            strLine += "\r\n";
            strLine += "Form1.VcChart1.RowCount =" + (short)numRow + ";";
            strLine += "\r\n";
            strLine += "Form1.VcChart1.ColumnCount =" + (short)(numCol - 1) + ";";
            strLine += "\r\n";
            //strLine+="Form1.VcChart1.ColumnCount ="+(short)(numCol-1)+"";
            strLine += "\r\n";

            for (int i = 0; i < numRow; i++)
            {

                for (int j = 1; j < numCol; j++)
                {
                    strLine += "Form1.VcChart1.Row =" + (short)(i + 1) + ";";
                    strLine += "\r\n";
                    strLine += "Form1.VcChart1.Column =" + (short)j + ";";
                    strLine += "\r\n";
                    strLine += "Form1.VcChart1.Data =\"" + ds.Tables[0].Rows[i][j].ToString() + "\";";
                    strLine += "\r\n";
                    //strLine+= "Form1.VcChart1.DataGrid .SetData(Form1.VcChart1.Row ,Form1.VcChart1.Column ,0,false);";
                    strLine += "\r\n";
                    strLine += "";
                    strLine += "\r\n";
                    strLine += "Form1.VcChart1.ColumnLabel =\"" + ds.Tables[0].Columns[j].ColumnName + "\";";
                    strLine += "\r\n";
                    strLine += "Form1.VcChart1.RowLabel=\"" + ds.Tables[0].Rows[i][0].ToString() + "\";";
                    strLine += "\r\n";


                }
            }
            //strLine+="Form1.VcChart1.DataUpdated()";

            //			Response.Write (strLine);
            strLine += "Form1.VcChart1.Legend.Location.Visible =true;";
            strLine += "\r\n";
            strLine += "Form1.VcChart1.Legend.Font .Size =10;";
            strLine += "\r\n";
            strLine += "}";
            strLine += "\r\n";
            strLine = strLine + "document.Form1.button1.style.visibility = \"visible\";";
            strLine += "\r\n";
            Literal1.Text = "";

            strLine += "-->";
            strLine += "\r\n";
            strLine += "</script>";
            strLine += "\r\n";
            Literal1.Text = strLine;

        }

        //绑定chart图表
        protected void BindPeople(string SQL)
        {

            YQCJDBLL bll = new YQCJDBLL();
             DataTable dt  = bll.QueryData(SQL);
            ChartPeople.DataSource = dt;
            ChartPeople.Series["WZJS"].XValueMember = "JB";
            ChartPeople.Series["WZJS"].XValueMember = "WZJS";
            ChartPeople.Series["DJSD1"].YValueMembers = "DJSD1";
            ChartPeople.Series["DJSD2"].YValueMembers = "DJSD2";
            ChartPeople.Series["QXJC"].YValueMembers = "QXJC";
            ChartPeople.Series["YXCD"].YValueMembers = "YXCD";
            ChartPeople.Series["SHL"].YValueMembers = "SHL";
            ChartPeople.DataBind();//绑定数据";
        }

        private void DataSetToExcelYC(string m_strSql, string strLine)
        {
            string strExcelFile = DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + ".xls";
            string strtmpDown = ConfigurationSettings.AppSettings["tmpDown"];
            strtmpDown = Request.PhysicalApplicationPath + strtmpDown + @"\" + Session["user_id"].ToString();
            if (!Directory.Exists(strtmpDown))
            {

                Directory.CreateDirectory(strtmpDown); //如果该目录不存在，建立该目录
            }


            string strFileName = strtmpDown + "\\" + strExcelFile; //形成带路径的文件名，型如：d:\dqweggis\ljt\temp\zyf\1.xls
            if (File.Exists(strFileName))
                try
                {
                    File.Delete(strFileName);//如果该文件已经存在，删除
                }
                catch (Exception ee)
                {
                    //throw ee;//删除文件失败时（例如该文件正在使用中）不做任何操作
                }

            //string strLine = "";
            StreamWriter sr = new StreamWriter(strFileName, false, System.Text.Encoding.GetEncoding("GB2312"));

           
            sr.WriteLine(strLine);
            YQCJDBLL bll = new YQCJDBLL();
            DataTable dt = bll.QueryData(m_strSql);
            sr.WriteLine(strLine);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                strLine = dt.Rows[i][0].ToString() + "\t" + dt.Rows[i][1].ToString() + "\t" +
                          dt.Rows[i][2].ToString() + "\t" + dt.Rows[i][3].ToString() + "\t" +
                          dt.Rows[i][4].ToString() + "\t" + dt.Rows[i][5].ToString() + "\t" +
                          dt.Rows[i][6].ToString() + "\t" + dt.Rows[i][7].ToString() + "\t";
                sr.WriteLine(strLine);
            }

            FileStream MyFileStream;
            long FileSize;
            try
            {
                MyFileStream = new FileStream(strFileName, FileMode.Open);
            }
            catch (Exception ee)
            {
                throw ee;
            }

            FileSize = MyFileStream.Length;

            byte[] Buffer = new byte[(int)FileSize];
            MyFileStream.Read(Buffer, 0, (int)FileSize);
            MyFileStream.Close();

            bool b = Response.Buffer;
            Response.Buffer = false;
            Response.Clear();
            Response.Charset = "GB2312";
            Response.ContentType = "application/x-msexcel";
            Response.AddHeader("Content-Length", FileSize.ToString());

            Response.AddHeader("Content-Disposition", "attachment;filename=\"" + strExcelFile + "\"");
            Response.BinaryWrite(Buffer);
            Response.Buffer = b;
            try
            {
                File.Delete(strFileName);
            }
            catch
            {
                //删除文件失败时（例如该文件正在使用中）不做任何操作
            }
        }

        private void DataSetToExcelYJ(string m_strSql, string strLine)
        {
            string strExcelFile = DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + ".xls";
            string strtmpDown = System.Configuration.ConfigurationSettings.AppSettings["tmpDown"]; 
            strtmpDown = Request.PhysicalApplicationPath + strtmpDown + @"\" + Session["user_id"].ToString();
            if (!Directory.Exists(strtmpDown))
            {

                Directory.CreateDirectory(strtmpDown); //如果该目录不存在，建立该目录
            }


            string strFileName = strtmpDown + "\\" + strExcelFile; //形成带路径的文件名，型如：d:\dqweggis\ljt\temp\zyf\1.xls
            if (File.Exists(strFileName))
                try
                {
                    File.Delete(strFileName);//如果该文件已经存在，删除
                }
                catch (Exception ee)
                {
                    //throw ee;//删除文件失败时（例如该文件正在使用中）不做任何操作
                }


            StreamWriter sr = new StreamWriter(strFileName, false, System.Text.Encoding.GetEncoding("GB2312"));


            YQCJDBLL bll = new YQCJDBLL();
            DataTable dt = bll.QueryData(m_strSql);
           
            sr.WriteLine(strLine);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                strLine = dt.Rows[i][0].ToString() + "\t" + dt.Rows[i][1].ToString() + "\t" +
                          dt.Rows[i][2].ToString() + "\t" + dt.Rows[i][3].ToString() + "\t" +
                          dt.Rows[i][4].ToString() + "\t" + dt.Rows[i][5].ToString() + "\t" +
                          dt.Rows[i][6].ToString() + "\t" + dt.Rows[i][7].ToString() + "\t";
                sr.WriteLine(strLine);
            }

            FileStream MyFileStream;
            long FileSize;
            try
            {
                MyFileStream = new FileStream(strFileName, FileMode.Open);
            }
            catch (Exception ee)
            {
                throw ee;
            }

            FileSize = MyFileStream.Length;

            byte[] Buffer = new byte[(int)FileSize];
            MyFileStream.Read(Buffer, 0, (int)FileSize);
            MyFileStream.Close();

            bool b = Response.Buffer;
            Response.Buffer = false;
            Response.Clear();
            Response.Charset = "GB2312";
            Response.ContentType = "application/x-msexcel";
            Response.AddHeader("Content-Length", FileSize.ToString());

            Response.AddHeader("Content-Disposition", "attachment;filename=\"" + strExcelFile + "\"");
            Response.BinaryWrite(Buffer);
            Response.Buffer = b;
            try
            {
                File.Delete(strFileName);
            }
            catch
            {
                //删除文件失败时（例如该文件正在使用中）不做任何操作
            }
        }

        #endregion 函数集

    }
}